package com.xuecheng.system.controller;

import com.xuecheng.commons.model.dto.LoginDto;
import com.xuecheng.commons.model.vo.LoginVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.UserVo;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.system.domain.User;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.system.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 用户信息前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class UserController {

    @Autowired
    private UserService  userService;

    //用户登录
    @PostMapping("/login")
    public ResponseResult<LoginVo> login(@RequestBody LoginDto loginDto){
        return userService.login(loginDto);
    }

    @GetMapping("/login/get")
    public ResponseResult<UserVo> getUserById(@RequestParam Long userId){
        //查询数据库
        User user = userService.getById(userId);
        //转vo
        UserVo userVo = BeanHelper.copyProperties(user, UserVo.class);
        return ResponseResult.okResult(userVo);
    }
}
